package com.fuershiye.woman.monitor.beans;

import java.util.List;

public class Pagination implements java.io.Serializable  {
    /**
     * 
     */
    private static final long serialVersionUID = -1806062339026050294L;
    private int rowCount;
    private int pageSize;
    private int limit;
    private int pageNum;
    private int allCount;
    private List<?> resultList;
    private String[] labels = new String[]{"|&lt;","&lt;","&gt;","&gt;|"};
    
    /**
     * {"第一页","上一页",下一页,"尾页"}
     * @return
     */
    public String[] getLabels() {
        return labels;
    }
    public void setLabels(String[] labels) {
        this.labels = labels;
    }
    /**
     * 
     * @return 总记录数
     */
    public int getRowCount() {
        return rowCount;
    }
    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
    }
    /**
     * @return 页数
     */
    public int getPageSize() {
        return pageSize;
    }
    
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    
    /**
     * 
     * @return 每页记录数
     */
    public int getLimit() {
        return limit;
    }
    public void setLimit(int limit) {
        this.limit = limit;
    }
    /**
     * 
     * @return 当前页数
     */
    public int getPageNum() {
        return pageNum;
    }
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }
    /**
     * 
     * @return 记录结果集
     */
    public List<?> getResultList() {
        return resultList;
    }
    public void setResultList(List<?> resultList) {
        this.resultList = resultList;
    }
    /**
     * 全部记录数量
     * @return
     */
    public int getAllCount() {
        return allCount;
    }
    public void setAllCount(int allCount) {
        this.allCount = allCount;
    }
    /**
     * 获得HTML分页显示
     * URL匹配模板
     * 替换规则
     * @param uriPattner
     * @return
     */
    public String getNavString(String uriPattner){
        StringBuffer sb = new StringBuffer();
        int nextPage = pageNum+1;
        int parentPage = pageNum-1;
        if(pageSize<=1){
            return "";
        }
        if(parentPage <= 1){
            parentPage = 1;
        }
        if(parentPage > pageSize){
            parentPage = pageSize;
        }
        if(nextPage >= pageSize){
            nextPage = pageSize;
        }
        sb.append("<strong><a href=\""+uriPattner.replaceAll("\\{p\\}","1")+"\">"+labels[0]+"</a></strong>");
        sb.append("<strong><a href=\""+uriPattner.replaceAll("\\{p\\}",Integer.toString(parentPage))+"\">"+labels[1]+"</a></strong>");
        for(int i=pageNum-10;i<pageNum+10;i++){
            if(i>=1&&i<=pageSize){
                if(i==pageNum){
                    sb.append("<font color=\"#FF0000\">"+i+"</font>");
                }else{
                    sb.append("<a href=\""+uriPattner.replaceAll("\\{p\\}",Integer.toString(i))+"\">"+i+"</a>");
                }
            }
        }
        sb.append("<strong><a href=\""+uriPattner.replaceAll("\\{p\\}",Integer.toString(nextPage))+"\">"+labels[2]+"</a></strong>");
        sb.append("<strong><a href=\""+uriPattner.replaceAll("\\{p\\}",Integer.toString(pageSize))+"\">"+labels[3]+"</a></strong>");
        return sb.toString();
    }
}